﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Workflow.Model
{
    public class WorkflowHasReceivedCls
    {
        public string WorkflowHasReceivedId;
        public string WorkflowDefId;
        public string WorkflowDefName;
        public string Subject;
        public string Description;
        public DateTime ReceivedDate;
        public string SendFromUser;
        public string Comment;
        public DateTime ProcessedDate;
    }

    public class WorkflowHasReceivedParser
    {
        public static WorkflowHasReceivedCls CreateInstance()
        {
            //tao 1 class trang....
            WorkflowHasReceivedCls oWorkflowHasReceivedCls = new WorkflowHasReceivedCls();
            return oWorkflowHasReceivedCls;
        }

        public static WorkflowHasReceivedCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            WorkflowHasReceivedCls oWorkflowHasReceivedCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oWorkflowHasReceivedCls;
        }


        public static WorkflowHasReceivedCls ParseFromDataRow(DataRow dr)
        {
            WorkflowHasReceivedCls oWorkflowHasReceivedCls = new WorkflowHasReceivedCls();

            oWorkflowHasReceivedCls.WorkflowHasReceivedId = XmlUtility.GetString(dr, "WorkflowHasReceivedId", true);
            oWorkflowHasReceivedCls.WorkflowDefId = XmlUtility.GetString(dr, "WorkflowDefId", true);
            oWorkflowHasReceivedCls.WorkflowDefName = XmlUtility.GetString(dr, "WorkflowDefName", true);
            oWorkflowHasReceivedCls.Subject = XmlUtility.GetString(dr, "Subject", true);
            oWorkflowHasReceivedCls.Description = XmlUtility.GetString(dr, "Description", true);
            oWorkflowHasReceivedCls.ReceivedDate = (DateTime)dr["ReceivedDate"];
            try
            {
                if (dr["ProcessedDate"] != DBNull.Value)
                {
                    oWorkflowHasReceivedCls.ProcessedDate = (DateTime)dr["ProcessedDate"];
                }
            }
            catch { }
            oWorkflowHasReceivedCls.SendFromUser = XmlUtility.GetString(dr, "SendFromUser", true);
            oWorkflowHasReceivedCls.Comment = XmlUtility.GetString(dr, "Comment", true);

            return oWorkflowHasReceivedCls;
        }

        public static WorkflowHasReceivedCls[] ParseFromDataTable(DataTable dtTable)
        {
            WorkflowHasReceivedCls[] SMSItems = new WorkflowHasReceivedCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                SMSItems[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return SMSItems;
        }

        public static WorkflowHasReceivedCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new WorkflowHasReceivedCls[0];
            }
            WorkflowHasReceivedCls[] SMSItems = new WorkflowHasReceivedCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                SMSItems[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return SMSItems;
        }
    }
}

